const Router = require('koa-router');
const router = new Router();
const tool = require('../../tools/tool')
const {db, QueryTypes} = require("../../models/db");

router.post('/menu/saveUsedMenu', async ctx => {
    try {
        let menuId = ctx.request.body.id;
        let adminId = ctx.user.id;
        let tenantId = ctx.user.tenantId;
        let obj = {
            menuId: menuId,
            adminId: adminId,
            tenantId: tenantId,
        }
        let model = await db.models['menuUsed'].findOne({
            where: obj
        })
        if(model) {
            await model.increment({times: 1})
        }
        else {
            obj.times = 1
            await db.models['menuUsed'].create( obj )
        }
        ctx.suc('')
    } catch (e) {
        return ctx.err(e)
    }
})
// 保存常用菜单


module.exports = router;
